export default function dateSelection(num, string) {
	//string 类型 只能传 MM  DD , YY等于年，MM等于月， DD 等于天
	//num 当前筛选的条件 0 代表当前 1等于今天 昨天；
	let date = new Date();
	let timestamp = date.getTime();//当天时间戳
	let day = date.getDate(); //获取当天
	let time = date.toLocaleDateString();//当前年月日
	let newDate = {
		beginTime:'',
		endTime:''
	}
	newDate.endTime = time;
	if (!string || string =='DD') {
		let newBegin = timestamp - Math.abs(num) * 3600 * 1000 * 24; //正数取开始时间
		if (num != Math.abs(num)) {
			newDate.endTime = new Date(newBegin).toLocaleDateString();
		}
		newDate.beginTime = new Date(newBegin).toLocaleDateString();
	}

	if (string == 'MM') {
		if (Math.abs(num) > 12) {
			return false;
		}
		if (num == 0) { //本月的开始时间
			var mm_month =  time.split("/");
			mm_month.splice(2, 1, '1');
			newDate.beginTime = mm_month.join("/");
		} else {
			let newEndTime = timestamp - day * 3600 * 1000 * 24 ;//这个是上个月最后一天时间戳
			let last = new Date(newEndTime).toLocaleDateString();//这个是上个月最后一天日期
			for (var i=0; i<Math.abs(num)-1; i++) {
				var dateArry = last.split('/')
				var dayString = dateArry[dateArry.length - 1];
				newEndTime = newEndTime - dayString* 3600 * 1000 * 24;
				last = new Date(newEndTime).toLocaleDateString(); //这个是上个月最后一天日期
			}
			if (num == Math.abs(num)) {
				var mm_current =  time.split("/");
				if (last.split("/")[2] < mm_current[2]) {
					mm_current[2] = last.split("/")[2]
				}
				if ((mm_current[1] - num) <= 0) {
					mm_current[0] = mm_current[0] -1;
					mm_current[1] = 12 - Math.abs(mm_current[1] - num);
				} else {
					mm_current.splice(1, 1, mm_current[1] - num)
				}
				newDate.beginTime = mm_current.join("/");
			} else {
				var mm_rvery =  last.split("/");
				mm_rvery.splice(2, 1, '1');
				newDate.beginTime = mm_rvery.join("/");
				newDate.endTime = new Date(newEndTime).toLocaleDateString();
			}
		}
	}
	// if(string =='YY'){

	// }
	return newDate;
};



// WEBPACK FOOTER //
// ./src/common/js/dateSelection.js